<%@ include file="/WEB-INF/jspf/tag-libraries.jspf"%>
<%@ taglib uri="http://displaytag.sf.net" prefix="display"%>
<ttjhome:bundle basename="candidates/candidates" />
<ttjhome:resource basename="candidates/candidates" bundle="errorBundle" scope="request" />
<ttjhome:rewrite var="editURL" action="/candidates/edit.do?action=edit" />
<script type="text/javascript">


function setExperiencesFilter(type,redirect){
	document.getElementById("experiences").innerHTML="&experience="+type;
	document.getElementById("experiences").style.display = "none"
	if(redirect==true)
		filter();
}
function setGenderFilter(type,redirect){
	document.getElementById("gender").innerHTML="&gender="+type;
	document.getElementById("gender").style.display = "none"
	if(redirect==true)
		filter();
}

function setTagsFilter(type,redirect){
	var tags = document.getElementById("tags").innerHTML;
	if(tags.indexOf(type) == -1){
	
	if(tags!=""){
		tags=tags+",";
	}
	tags=tags+type;
	document.getElementById("tags").innerHTML=tags;
	document.getElementById("tags").style.display = "none"
	if(redirect==true)
		filter();
   }
}


function filter(){
	var url=document.getElementById("experiences").innerHTML;
	url=url+document.getElementById("gender").innerHTML;
	
    var amp = new RegExp("&amp;", "g");
	url= url.replace(amp, "&");
	url=url+"&tags="+document.getElementById("tags").innerHTML;
	var fullurl = document.getElementById("candidateFilterForm").action+url;
	document.getElementById("candidateFilterForm").action=encodeURI(fullurl);
	
	document.getElementById("candidateFilterForm").method="post";
	document.getElementById("candidateFilterForm").submit();
}

$(document).ready(function() {
     
	var experience = $.query.get("experience");
	if(experience != ""){
		setExperiencesFilter(experience,false);
	}
	var gender = $.query.get("gender");
	if(gender!=""){
		setGenderFilter(gender,false);
	}
	var tags = $.query.get("tags");
	if(tags!=""){
		setTagsFilter(tags,false);
	}
	
})

</script>

<c:set var="jobId" value="${candidateQueryForm.map.jobId}"/>



<div class="toolBody">
	<div id="error" class="couponErrMsg">
		<tiles:insert definition="errors-page-header">
			<tiles:put name="errorStyle" value="err-msg" />
			<tiles:put name="errorIcon" value="/include/img/error-sign-sm.gif" />
		</tiles:insert>
	</div>
	<html:form method="post" action="/candidates/list.do?action=list"   styleId="candidateFilterForm">
	<div  class="candidateFilter">
		
		<div class="odd">
			<span><fmt:message key="candidate.experiences"/></span>
			<a  href="javascript: void(0)" onclick="javascript:setExperiencesFilter(1,true);return false;"><fmt:message key="experiences.0.3"/></a> 
			<a  href="javascript: void(0)" onclick="javascript:setExperiencesFilter(2,true);return false;"><fmt:message key="experiences.3"/></a>
			<a  href="javascript: void(0)" onclick="javascript:setExperiencesFilter(3,true);return false;"><fmt:message key="experiences.5"/></a>
			<a  href="javascript: void(0)" onclick="javascript:setExperiencesFilter(4,true);return false;"><fmt:message key="experiences.8"/></a>
			<a  href="javascript: void(0)" onclick="javascript:setExperiencesFilter(5,true);return false;"><fmt:message key="experiences.10"/></a>
		</div>
	
		<div class="even">
			<span><fmt:message key="candidate.gender"/></span>
			<a  href="javascript: void(0)" onclick="javascript:setGenderFilter('male',true);return false;"><fmt:message key="gender.male"/></a>
			<a  href="javascript: void(0)" onclick="javascript:setGenderFilter('female',true);return false;"><fmt:message key="gender.female"/></a>
		</div>
	
		<div id="experiences"></div>
		<div id="gender"></div>
		<div id="tags"></div>
	</div>	
	</html:form>

	<h2 class="toolH2">Candidates</h2>
	<div class="candidatesList">
	<div class="leftCol">&nbsp;</div>


	<c:if test="${candidatesCount>0}">
		<fmt:message key="page.first" var="pageFirst"/>
		<fmt:message key="page.prev" var="pagePrev"/>
		<fmt:message key="page.next" var="pageNext"/>
		<fmt:message key="page.last" var="pageLast"/>
		<display:table requestURI="/candidates/list.do?action=list" name="candidatesList" pagesize="5" sort="external" class="candidatesTable" defaultsort="4" id="candidate" partialList="true" size="${candidatesCount}">
			<display:setProperty name="paging.banner.onepage" value="" />
			<display:setProperty name="paging.banner.first" value="<span class='pagelinks'><span class='pageunselected'>${pageFirst}</span> <span class='pageunselected'>${pagePrev}</span> {0} <a href={3}>${pageNext}</a> <a href={4}>${pageLast}</a></span>" />
			<display:setProperty name="paging.banner.last" value="<span class='pagelinks'><a href={1}>${pageFirst}</a> <a href={2}>${pagePrev}</a> {0} <span class='pageunselected'>${pageNext}</span> <span class='pageunselected'>${pageLast}</span></span>" />
			<display:setProperty name="paging.banner.full" value="<span class='pagelinks'><a href={1}>${pageFirst}</a> <a href={2}>${pagePrev}</a> {0} <a href={3}>${pageNext}</a> <a href={4}>${pageLast}</a></span>" />
			<display:setProperty name="paging.banner.page.selected" value="<span class='pageselected'>{0}</span>" />
			<display:setProperty name="paging.banner.page.separator" value="&nbsp;" />
			<display:setProperty name="paging.banner.placement" value="both" />			
			<display:setProperty name="paging.banner.some_items_found" value="<span class='ptext'>Candidates {2} to {3}</span>" />
			<c:choose>
				<c:when test="${candidatesCount>1}">
					<display:setProperty name="paging.banner.all_items_found" value="<span class='ptext'>find all</span>" />
				</c:when>
				<c:otherwise >
					<display:setProperty name="paging.banner.all_items_found" value="" />
				</c:otherwise>
			</c:choose>
			
			<fmt:message key="candidate.name" var="candidateName"/>
			<display:column  title="${candidateName}"   >
			<c:choose>
				<c:when test="${not empty jobId}">
					<div ><a  href="javascript: void(0)" onclick="javascript:location.href='${editURL}&candidateID=${candidate.id}&jobId=${jobId}';return false;">${candidate.name}</a></div>
				</c:when>
				<c:otherwise >
					<div ><a  href="javascript: void(0)" onclick="javascript:location.href='${editURL}&candidateID=${candidate.id}';return false;">${candidate.name}</a></div>
				</c:otherwise>
			</c:choose>
				
			</display:column>	
			<fmt:message key="candidate.gender" var="candidateGender"/>
			<display:column  title="${candidateGender}"  sortable="true" sortName="gender"  >
				<div >${candidate.gender}</div>
			</display:column>	
			<fmt:message key="candidate.age" var="candidateAge"/>
			<display:column  title="${candidateAge}"  sortable="true" sortName="age"  >
				<c:choose>
					<c:when test="${candidate.age==-1}"><fmt:message key="unknown"/></c:when>
					<c:otherwise><div >${candidate.age}</div></c:otherwise>
				</c:choose> 
			</display:column>
			<fmt:message key="candidate.experiences" var="candidateExperience"/>
			<display:column  title="${candidateExperience}"  sortable="true" sortName="experiences"  >
				<c:choose>
					<c:when test="${candidate.experiences==-1}"><fmt:message key="unknown"/></c:when>
					<c:otherwise><div >${candidate.experiences} (years)</div></c:otherwise>
				</c:choose> 
			</display:column>
			<fmt:message key="candidate.resumes" var="candidateResumes"/>
			<display:column  title="${candidateResumes}"  >
				<c:choose>
					
							<c:forEach var="resume" items="${candidate.resumes}" varStatus="iStat">
								<div ><a href=${resume.url}>${resume.filename}</a></div>
							</c:forEach>
					
				</c:choose> 
			</display:column>	
			<fmt:message key="candidate.tags" var="candidateTags"/>
			<display:column  title="${candidateTags}"  >
				<c:choose>
					<c:forEach var="tag" items="${candidate.tags}" varStatus="iStat">
							${tag.tag}
					</c:forEach>
				</c:choose> 
			</display:column>	

		</display:table>
	</c:if>
</div>
</div>
